// 导航守卫
import store from '@/store';
import router from '@/router';

router.beforeEach(async (to, from, next) => {
  const { token } = store.state.user;

  if (token) {
    next();
    return;
  }

  if (to.path === '/login') {
    if (token) {
      next('/');
      return;
    }
    next();
    return;
  }

  next('/login');
});
